package com.bolt.report.definition;

import com.bolt.common.utils.StrUtil;
import com.bolt.report.engine.BindData;
import com.bolt.report.engine.fill.FillContext;
import com.bolt.report.engine.fill.HyperlinkData;
import com.bolt.report.engine.model.Expression;
import com.fasterxml.jackson.databind.JsonNode;

import java.io.Serializable;

public class CellDefinition implements Serializable {

    private String name;

    private String key;

    private String valueClassName = java.lang.String.class.getName();

    private Class<?> valueClass;

    private String expression;

    private int width;

    private int height;

    private int cellWidth;

    private int cellHeight;

    private StyleDefinition style;

    private DataExpand dataExpand;

    private ElementType elementType;

    private HyperlinkData hyperlinks;

    protected int x;

    protected int y;

    private boolean group;

    private boolean hide;

    private boolean sort;

    private SortOrder sortOrder;

    private int colSpan;

    private int rowSpan;

    private JsonNode jsonData;

    private String labels;

    private String img;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getValueClassName() {
        return valueClassName;
    }

    public void setValueClassName(String valueClassName) {
        this.valueClassName = valueClassName;
    }

    public Class<?> getValueClass() {
        return valueClass;
    }

    public void setValueClass(Class<?> valueClass) {
        this.valueClass = valueClass;
    }

    public String getExpression() {
        return expression;
    }

    public void setExpression(String expression) {
        this.expression = expression;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public StyleDefinition getStyle() {
        if (this.style != null) {
            style.setWidth(getWidth());
        }
        return style;
    }

    public void setStyle(StyleDefinition style) {
        this.style = style;
    }

    public boolean isHide() {
        return hide;
    }

    public void setHide(boolean hide) {
        this.hide = hide;
    }

    public DataExpand getDataExpand() {
        return dataExpand;
    }

    public void setDataExpand(DataExpand dataExpand) {
        this.dataExpand = dataExpand;
    }

    public boolean isGroup() {
        return group;
    }

    public void setGroup(boolean group) {
        this.group = group;
    }

    public boolean isSort() {
        return sort;
    }

    public void setSort(boolean sort) {
        this.sort = sort;
    }

    public SortOrder getSortOrder() {
        return sortOrder;
    }

    public void setSortOrder(SortOrder sortOrder) {
        this.sortOrder = sortOrder;
    }


    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public ElementType getElementType() {
        return elementType;
    }

    public void setElementType(ElementType elementType) {
        this.elementType = elementType;
    }

    public int getColSpan() {
        return colSpan;
    }

    public void setColSpan(int colSpan) {
        this.colSpan = colSpan;
    }

    public int getRowSpan() {
        return rowSpan;
    }

    public void setRowSpan(int rowSpan) {
        this.rowSpan = rowSpan;
    }

    public JsonNode getJsonData() {
        return jsonData;
    }

    public void setJsonData(JsonNode jsonData) {
        this.jsonData = jsonData;
    }

    public String getLabels() {
        return labels;
    }

    public void setLabels(String labels) {
        this.labels = labels;
    }

    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getCellWidth() {
        return this.colSpan > 0 ? cellWidth * this.colSpan : this.cellWidth;
    }

    public void setCellWidth(int cellWidth) {
        this.cellWidth = cellWidth;
    }

    public int getCellHeight() {
        return this.rowSpan > 0 ? cellHeight * this.rowSpan : this.cellHeight;
    }

    public void setCellHeight(int cellHeight) {
        this.cellHeight = cellHeight;
    }

    public boolean isDataSetCell(FillContext fillContext) {
        return StrUtil.isBlank(this.key) && getElementType() == ElementType.TEXT ;
    }

    public HyperlinkData getHyperlinks() {
        return hyperlinks;
    }

    public void setHyperlinks(HyperlinkData hyperlinks) {
        this.hyperlinks = hyperlinks;
    }

    public Expression getExpressionObj(BindData bindData) {

            return new Expression(getExpression(), bindData);


    }
}